<?php
if (!defined('FosfoaSystem')){exit(1);}
import($GLOBALS['spConfig']['controller_path'] . '/general.php');
class pic2 extends general
{
    public function __construct()
    {
        parent::__construct();
        $this->tpl_title = T("Dashboard");
        $this->navigation_current = 'categories';
        $this->categories = spClass('newscategoriesModel')->spLinker()->findAll(null,'sort_order asc,categories_id asc');
    }
    function index()
    {
        $this->tt = "图库管理";
        $news_id=$this->spArgs("news_id",0);
        $obj = spClass("newsModel");
        if($news_id==0){
            echo "<a href=''>出错了!------点这里后退</a>";
        }
        $obj->linker[0]['field'] = 'news_name';
        $conditions = array('news_id' => $news_id);

        $arr = $obj->spLinker()->find($conditions,'','news_id,news_allimg,news_image');
        $this->allimg=unserialize($arr['news_allimg']);
        $this->imgname = $arr['detail']['news_name'];
        $this->img=$arr['news_image'];
        $this->news_id=$arr['news_id'];
        $this->display("admin/pic2_index.html");
    }
    function del()
    {
        $news_id=$this->spArgs("news_id",0);
        $id=$this->spArgs("id");
        $zt=$this->spArgs("zt");
        $xt=$this->spArgs("xt");
        if($news_id==0){
            $this->error('不存在此作品');
            //echo "<a href=''>出错了!------点这里后退</a>";
        }
        $obj = spClass("newsModel");
        $conditions = array('news_id' => $news_id);

        $arr = $obj->find($conditions,'','news_id,news_allimg,news_image');
        $allimg=unserialize($arr['news_allimg']);
        $delimg=$allimg[$id];
        unset($allimg[$id]);
        if (file_exists("upload/".$delimg)) {
        @unlink ("upload/".$delimg);
        }
        $allimg=serialize($allimg);
        $data=array('news_allimg'=>$allimg);
        if($zt){
            $data['news_image']='';
        }
        if($xt){
           $data['news_smallimg']=''; 
        }
        //dump($data); 
        $tt=$obj->update($conditions, $data);
        $msg="删除商品图片".$delimg;
        Savelog($msg);
        $this->success('删除成功');
              
    }
}